package com.lionel.helloworld;
import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.ActiveMQConnectionFactory;
import javax.jms.*;
import java.util.concurrent.TimeUnit;

/**
 * @author 714936489@qq.com
 * @date 2018/5/20 17:47
 */
@Slf4j
public class Sender {
    public static void main(String[] args) throws Exception{
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
                ActiveMQConnectionFactory.DEFAULT_USER,
                ActiveMQConnectionFactory.DEFAULT_PASSWORD,
                "tcp://localhost:61616"
        );
        Connection connection = connectionFactory.createConnection();
        connection.start();
        Session session = connection.createSession(Boolean.FALSE, Session.AUTO_ACKNOWLEDGE);
        Destination destination = session.createQueue("first");
        MessageProducer producer= session.createProducer(null);
        for (int i = 0;i<100;i++){
            TextMessage msg = session.createTextMessage("我是消息类容" + i);
            producer.send(destination,msg);
            TimeUnit.SECONDS.sleep(1);
            log.info("生产数据：{}",msg.getText());
        }
        if(connection!=null){
            connection.close();
        }
    }
}
